package cn.ware.house.interfaces.service.impl;

import cn.ware.house.interfaces.entity.Inventory;
import cn.ware.house.interfaces.mapper.InventoryMapper;
import cn.ware.house.interfaces.service.InventoryService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * 库存服务接口的实现类，实现了库存业务逻辑操作的具体方法，
 * 通过调用库存数据访问层（InventoryMapper）的方法来与数据库进行交互，
 * 完成如查询、插入、更新、删除等业务功能。
 */
@Service
public class InventoryServiceImpl implements InventoryService {

    @Resource
    private InventoryMapper inventoryMapper;

    @Override
    public List<Inventory> findInventoriesByPage(int page, int size) {
        int offset = (page - 1) * size;
        return inventoryMapper.selectInventoriesByPage(offset, size);
    }
    @Override
    public Inventory findInventoryById(Integer inventoryId) {
        return inventoryMapper.selectInventoryById(inventoryId);
    }

    @Override
    public List<Inventory> findAllInventories() {
        return inventoryMapper.selectAllInventories();
    }

    @Override
    public boolean insertInventory(Inventory inventory) {
        int rows = inventoryMapper.insertInventory(inventory);
        return rows > 0;
    }

    @Override
    public boolean updateInventoryById(Inventory inventory) {
        int rows = inventoryMapper.updateInventoryById(inventory);
        return rows > 0;
    }

    @Override
    public boolean deleteInventoryById(Integer inventoryId) {
        int rows = inventoryMapper.deleteInventoryById(inventoryId);
        return rows > 0;
    }

    @Override
    public int findTotalCount() {

        return inventoryMapper.selectTotalCount();
    }
}